# Commands 

CC := gcc
LDCMD := ld
OBJDUMP_CMD := objdump

# Directories

BOOTDIR := ../boot
OBJDIR := ../objs
FLPDIR := ../flp

# Flags 

INCLUDES := -I ../headers
CFLAGS := -fno-stack-protector -nostdinc -fno-builtin -W -Wall $(INCLUDES)
LDFLAGS := -Ttext=0x1000 --oformat binary
OBJDUMP_FLAGS := -r -d -M intel -S

# Object Files and Source Files

OBJS := k_init.o functions.o idt.o memory.o isrs.o timer.o irq.o console.o math.o scrn.o kb.o kernel.o new.o pci.o io.o pack.o chksum.o icmp.o ip.o pcnet33.o
SRCS := k_init.c functions.c idt.c memory.c isrs.c timer.c irq.c console.c math.c scrn.c kb.c kernel.c pci.c io.c pack.c chksum.c icmp.c ip.c pcnet33.c

# Rules

all: kernel boot flp objdump

kernel: $(OBJS)
	$(LDCMD) $(LDFLAGS) $(OBJS) -o kernel
	test -d $(OBJDIR) || mkdir $(OBJDIR)
	mv *.o $(OBJDIR)
	mv kernel $(OBJDIR)

%.c.o: 
	$(CC) $< $(CFLAGS) -o $@

objdump:
	$(OBJDUMP_CMD) $(OBJDUMP_FLAGS) $(OBJDIR)/*.o > $(OBJDIR)/objdump.txt

new.o: 	
	nasm -f aout -o new.o new.asm

boot: 	
	test -d $(BOOTDIR) || mkdir $(BOOTDIR)
	nasm -f bin -o $(BOOTDIR)/boot boot.asm


clean:
	rm -f $(OBJDIR)/* $(BOOTDIR)/*  $(FLPDIR)/* objdump.txt *~
	rm -f *.o

flp:
	test -d $(FLPDIR) || mkdir $(FLPDIR)
	dd if=/dev/zero of=$(FLPDIR)/fileb.flp bs=2880k count=1
	cat $(BOOTDIR)/boot $(OBJDIR)/kernel > $(FLPDIR)/fileb.flpx
	dd if=$(FLPDIR)/fileb.flpx of=$(FLPDIR)/fileb.flp conv=notrunc
